<template>
  <div class="test-report">
    <!-- 页面标题 -->
    <h2 class="report-title">测试报告</h2>

    <!-- 搜索框 -->
    <div class="search-section" style="display: flex; gap: 10px; align-items: center;">
      <el-select v-model="selectedTest" placeholder="选择测试报告" @change="filterReports">
        <el-option label="全部测试" value="all" />
        <el-option label="测试 #1" value="test1" />
        <el-option label="测试 #2" value="test2" />
      </el-select>
      <el-input v-model="searchTest" placeholder="测试用例" style="max-width: 200px;" />
      <el-button type="primary" @click="searchReports">查询</el-button>
      <el-button @click="resetSearch">重置</el-button>
    </div>

    <!-- 操作按钮 -->
    <div class="action-buttons">
      <el-button type="primary" icon="el-icon-plus" @click="addTestReport">新增</el-button>
      <el-button type="success" icon="el-icon-download" @click="exportReports">导出</el-button>
      <el-button type="warning" icon="el-icon-upload2" @click="importReports">导入</el-button>
    </div>

    <!-- 测试用例表格 -->
    <el-table :data="filteredReports" style="width: 100%" stripe>
      <el-table-column prop="startTime" label="开始测试时间" align="center" show-overflow-tooltip />
      <el-table-column prop="endTime" label="结束测试时间" align="center" show-overflow-tooltip />
      <el-table-column prop="testCount" label="测试次数" align="center" show-overflow-tooltip />
      <el-table-column prop="bytecode" label="字节码" align="center" show-overflow-tooltip width="300" />
      <el-table-column prop="result" label="测试结果" align="center" show-overflow-tooltip />
      <el-table-column prop="timeTaken" label="执行时间" align="center" show-overflow-tooltip />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="viewTestDetails(scope.row)">查看详情</el-button>
        </template>
      </el-table-column>
      <el-table-column label="报告操作" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="downloadReport(scope.row)">下载测试报告</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      layout="total, prev, pager, next"
      :total="filteredReports.length"
      :page-size="pageSize"
      @current-change="handlePageChange"
    />

    <!-- 测试详情弹窗 -->
    <el-dialog :visible.sync="testDetailsVisible" width="60%" title="测试详情">
      <h3>测试用例详情</h3>
      <el-card style="margin-top: 20px;">
        <div slot="header" class="clearfix">
          <span>测试用例详情</span>
        </div>
        <el-table :data="[testDetails]" style="width: 100%">
          <el-table-column prop="bytecode" label="字节码" align="center" width="300" />
          <el-table-column prop="result" label="结果" align="center" width="100" />
          <el-table-column prop="timeTaken" label="执行时间" align="center" width="120" />
        </el-table>
      </el-card>

      <!-- 覆盖率报告 -->
      <h3>覆盖率报告</h3>
      <el-card style="margin-top: 20px;">
        <div slot="header" class="clearfix">
          <span>覆盖率报告</span>
        </div>
        <el-row>
          <el-col :span="12">
            <p><strong>函数级覆盖率:</strong> {{ testDetails.functionCoverage }}%</p>
          </el-col>
          <el-col :span="12">
            <p><strong>包级覆盖率:</strong> {{ testDetails.packageCoverage }}%</p>
          </el-col>
        </el-row>
      </el-card>

      <!-- 差分测试结果 -->
      <h3>差分测试结果</h3>
      <el-card style="margin-top: 20px;">
        <div slot="header" class="clearfix">
          <span>差分测试结果</span>
        </div>
        <el-table :data="testDetails.differentialResults" style="width: 100%">
          <el-table-column prop="evm" label="EVM实现" align="center" width="180" />
          <el-table-column prop="result" label="测试结果" align="center" />
          <el-table-column prop="gasUsed" label="Gas消耗" align="center" width="120" />
          <el-table-column prop="stackState" label="栈状态" align="center" width="150" />
          <el-table-column prop="storageState" label="存储状态" align="center" width="150" />
        </el-table>
      </el-card>

      <!-- 漏洞与问题汇总 -->
      <h3>漏洞与问题汇总</h3>
      <el-card style="margin-top: 20px;">
        <div slot="header" class="clearfix">
          <span>漏洞与问题汇总</span>
        </div>
        <el-table :data="testDetails.issues" style="width: 100%">
          <el-table-column prop="issueId" label="漏洞ID" align="center" width="120" />
          <el-table-column prop="description" label="描述" align="center" />
          <el-table-column prop="status" label="状态" align="center" width="100" />
        </el-table>
      </el-card>

      <!-- 修复建议 -->
      <h3>修复建议</h3>
      <el-card style="margin-top: 20px;">
        <div slot="header" class="clearfix">
          <span>修复建议</span>
        </div>
        <el-table :data="testDetails.fixSuggestions" style="width: 100%">
          <el-table-column prop="opcode" label="操作码" align="center" width="150" />
          <el-table-column prop="suggestion" label="修复建议" align="center" />
        </el-table>
      </el-card>

      <span slot="footer" class="dialog-footer">
        <el-button @click="testDetailsVisible = false">关闭</el-button>
      </span>
    </el-dialog>

    <!-- 新增测试报告弹窗 -->
    <el-dialog :visible.sync="addReportVisible" width="60%" title="新增测试报告">
      <el-form :model="newReport" label-width="120px">
        <el-form-item label="字节码">
          <el-input v-model="newReport.bytecode" />
        </el-form-item>
        <el-form-item label="测试结果">
          <el-select v-model="newReport.result">
            <el-option label="成功" value="成功" />
            <el-option label="失败" value="失败" />
          </el-select>
        </el-form-item>
        <el-form-item label="执行时间">
          <el-input v-model="newReport.timeTaken" />
        </el-form-item>
        <el-form-item label="开始时间">
          <el-date-picker v-model="newReport.startTime" type="datetime" placeholder="选择开始时间" />
        </el-form-item>
        <el-form-item label="结束时间">
          <el-date-picker v-model="newReport.endTime" type="datetime" placeholder="选择结束时间" />
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="addReportVisible = false">取消</el-button>
        <el-button type="primary" @click="saveNewReport">保存</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
export default {
  data() {
    return {
      selectedTest: 'all', // 默认显示所有测试报告
      testReports: [
        {
          'testCaseId': 'test2',
          'name': 'Geth漏洞修复',
          'platform': 'geth',
          'description': '执行操作码basefee返回值不正确，未采用genesis中设置的值',
          'date': '2024-09-08',
          'status': '已修复',
          'crashLog': 'Traceback (most recent call last):\n  File "/path/to/evm/evm.py", line 200, in execute\n    self.create_contract()\n  File "/path/to/evm/evm.py", line 150, in create_contract\n    raise Exception("BASEFEE value mismatch detected")\nException: BASEFEE value mismatch detected',
          'bytecode': '4860005260406000f3',
          'result': '失败',
          'timeTaken': '3s',
          'startTime': '2024-10-13 10:00',
          'endTime': '2024-10-13 10:45',
          'testCount': 2,
          'executionLog': 'Traceback (most recent call last):File "/path/to/evm/evm.py", line 200, in execute self.create_contract() File "/path/to/evm/evm.py", line 150, in create_contract raise Exception("BASEFEE value mismatch detected")Exeption: BASEFEE value mismatch detected',
          'opcodeTrace': [
            { 'step': 1, 'opcode': 'BASEFEE', 'description': '获取区块的基础费用' },
            { 'step': 2, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 3, 'opcode': 'MSTORE', 'description': '将栈顶的值存入内存' },
            { 'step': 4, 'opcode': 'PUSH1', 'description': '将值40推入栈' },
            { 'step': 5, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 6, 'opcode': 'RETURN', 'description': '返回内存中的数据' }
          ],
          'rootCause': 'BASEFEE操作码未能使用genesis.json中指定的baseFeePerGas值，导致返回值不正确。',
          'functionCoverage': 38.55, // 覆盖率报告部分
          'packageCoverage': 35.65, // 覆盖率报告部分
          'differentialResults': [
            {
              evm: 'Geth',
              result: '通过',
              gasUsed: '0xa3d', // Geth的Gas消耗
              stackState: '正常',
              storageState: '一致',
              output: '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
            },
            {
              evm: 'SealEVM',
              result: '失败',
              gasUsed: '0x6', // SealEVM的Gas消耗
              stackState: '异常',
              storageState: '不一致',
              error: 'no code for: 0x24d82e387fcccb6c675d75947bf2e8e09fbea57d' // SealEVM的错误信息
            }
          ],
          'issues': [
            { 'issueId': 'EXTCODESIZE', 'description': '外部合约调用失败，未找到合约代码', 'status': '待修复' },
            { 'issueId': 'PUSH20', 'description': 'Gas消耗差异', 'status': '待修复' },
            { 'issueId': 'RETURN', 'description': 'Geth返回有效输出，SealEVM未返回', 'status': '待修复' }
          ],
          'fixSuggestions': [
            { 'opcode': 'EXTCODESIZE', 'suggestion': '检查合约代码的部署状态或合约地址的正确性' },
            { 'opcode': 'PUSH20', 'suggestion': '优化合约代码逻辑，减少无效的Gas消耗' },
            { 'opcode': 'RETURN', 'suggestion': '确保SealEVM正确处理返回值' }
          ]
        },
        {
          'testCaseId': 'test2',
          'name': 'PY-EVM',
          'platform': 'geth',
          'description': '执行操作码basefee返回值不正确，未采用genesis中设置的值',
          'date': '2024-08-08',
          'status': '已修复',
          'crashLog': 'Traceback (most recent call last):\n  File "/path/to/evm/evm.py", line 200, in execute\n    self.create_contract()\n  File "/path/to/evm/evm.py", line 150, in create_contract\n    raise Exception("BASEFEE value mismatch detected")\nException: BASEFEE value mismatch detected',
          'bytecode': '60206000610a2a3760b35160005260406000f3',
          'result': '成功',
          'timeTaken': '2s',
          'startTime': '2024-10-11 11:00',
          'endTime': '2024-10-11 10:45',
          'testCount': 8,
          'executionLog': '',
          'opcodeTrace': [
            { 'step': 1, 'opcode': 'BASEFEE', 'description': '获取区块的基础费用' },
            { 'step': 2, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 3, 'opcode': 'MSTORE', 'description': '将栈顶的值存入内存' },
            { 'step': 4, 'opcode': 'PUSH1', 'description': '将值40推入栈' },
            { 'step': 5, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 6, 'opcode': 'RETURN', 'description': '返回内存中的数据' }
          ],
          'rootCause': 'BASEFEE操作码未能使用genesis.json中指定的baseFeePerGas值，导致返回值不正确。',
          'functionCoverage': 38.55, // 覆盖率报告部分
          'packageCoverage': 35.65, // 覆盖率报告部分
          'differentialResults': [
            {
              evm: 'Geth',
              result: '通过',
              gasUsed: '0xa3d', // Geth的Gas消耗
              stackState: '正常',
              storageState: '一致',
              output: '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
            },
            {
              evm: 'SealEVM',
              result: '通过',
              gasUsed: '0x6', // SealEVM的Gas消耗
              stackState: '正常',
              storageState: '一致',
              output: '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
            }
          ],
          'issues': [
            // { "issueId": 'EXTCODESIZE', "description": "外部合约调用失败，未找到合约代码", "status": "待修复" },
            // { "issueId": 'PUSH20', "description": "Gas消耗差异", "status": "待修复" },
            // { "issueId": 'RETURN', "description": "Geth返回有效输出，SealEVM未返回", "status": "待修复" }
          ],
          'fixSuggestions': [
            // { "opcode": 'EXTCODESIZE', "suggestion": "检查合约代码的部署状态或合约地址的正确性" },
            // { "opcode": 'PUSH20', "suggestion": "优化合约代码逻辑，减少无效的Gas消耗" },
            // { "opcode": 'RETURN', "suggestion": "确保SealEVM正确处理返回值" }
          ]
        },
        {
          'testCaseId': 'test2',
          'name': 'SealEVM漏洞修复',
          'platform': 'geth',
          'description': '执行操作码basefee返回值不正确，未采用genesis中设置的值',
          'date': '2024-08-08',
          'status': '已修复',
          'crashLog': 'Traceback (most recent call last):\n  File "/path/to/evm/evm.py", line 200, in execute\n    self.create_contract()\n  File "/path/to/evm/evm.py", line 150, in create_contract\n    raise Exception("BASEFEE value mismatch detected")\nException: BASEFEE value mismatch detected',
          'bytecode': '6a30f68d9062133d08b4b0ea7cc78e8203',
          'result': '失败',
          'timeTaken': '3s',
          'startTime': '2024-10-09 10:00',
          'endTime': '2024-10-09 10:45',
          'testCount': 10,
          'executionLog': 'Traceback (most recent call last):File "/path/to/evm/evm.py", line 200, in execute self.create_contract() File "/path/to/evm/evm.py", line 150, in create_contract raise Exception("BASEFEE value mismatch detected")Exeption: BASEFEE value mismatch detected',
          'opcodeTrace': [
            { 'step': 1, 'opcode': 'BASEFEE', 'description': '获取区块的基础费用' },
            { 'step': 2, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 3, 'opcode': 'MSTORE', 'description': '将栈顶的值存入内存' },
            { 'step': 4, 'opcode': 'PUSH1', 'description': '将值40推入栈' },
            { 'step': 5, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 6, 'opcode': 'RETURN', 'description': '返回内存中的数据' }
          ],
          'rootCause': 'BASEFEE操作码未能使用genesis.json中指定的baseFeePerGas值，导致返回值不正确。',
          'functionCoverage': 38.55, // 覆盖率报告部分
          'packageCoverage': 35.65, // 覆盖率报告部分
          'differentialResults': [
            {
              evm: 'Geth',
              result: '通过',
              gasUsed: '0xa3d', // Geth的Gas消耗
              stackState: '正常',
              storageState: '一致',
              output: '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
            },
            {
              evm: 'SealEVM',
              result: '失败',
              gasUsed: '0x6', // SealEVM的Gas消耗
              stackState: '异常',
              storageState: '不一致',
              error: 'no code for: 0x24d82e387fcccb6c675d75947bf2e8e09fbea57d' // SealEVM的错误信息
            }
          ],
          'issues': [
            { 'issueId': 'EXTCODESIZE', 'description': '外部合约调用失败，未找到合约代码', 'status': '待修复' },
            { 'issueId': 'PUSH20', 'description': 'Gas消耗差异', 'status': '待修复' },
            { 'issueId': 'RETURN', 'description': 'Geth返回有效输出，SealEVM未返回', 'status': '待修复' }
          ],
          'fixSuggestions': [
            { 'opcode': 'EXTCODESIZE', 'suggestion': '检查合约代码的部署状态或合约地址的正确性' },
            { 'opcode': 'PUSH20', 'suggestion': '优化合约代码逻辑，减少无效的Gas消耗' },
            { 'opcode': 'RETURN', 'suggestion': '确保SealEVM正确处理返回值' }
          ]
        },
        {
          'testCaseId': 'test2',
          'name': 'execution-specs漏洞修复',
          'platform': 'geth',
          'description': '执行操作码basefee返回值不正确，未采用genesis中设置的值',
          'date': '2024-08-08',
          'status': '已修复',
          'crashLog': 'Traceback (most recent call last):\n  File "/path/to/evm/evm.py", line 200, in execute\n    self.create_contract()\n  File "/path/to/evm/evm.py", line 150, in create_contract\n    raise Exception("BASEFEE value mismatch detected")\nException: BASEFEE value mismatch detected',
          'bytecode': '7f5e238a584484ea938bea8568a00',
          'result': '失败',
          'timeTaken': '3s',
          'startTime': '2024-10-16 10:04',
          'endTime': '2024-10-16 10:35',
          'testCount': 2,
          'executionLog': 'Traceback (most recent call last):File "/path/to/evm/evm.py", line 200, in execute self.create_contract() File "/path/to/evm/evm.py", line 150, in create_contract raise Exception("BASEFEE value mismatch detected")Exeption: BASEFEE value mismatch detected',
          'opcodeTrace': [
            { 'step': 1, 'opcode': 'BASEFEE', 'description': '获取区块的基础费用' },
            { 'step': 2, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 3, 'opcode': 'MSTORE', 'description': '将栈顶的值存入内存' },
            { 'step': 4, 'opcode': 'PUSH1', 'description': '将值40推入栈' },
            { 'step': 5, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 6, 'opcode': 'RETURN', 'description': '返回内存中的数据' }
          ],
          'rootCause': 'BASEFEE操作码未能使用genesis.json中指定的baseFeePerGas值，导致返回值不正确。',
          'functionCoverage': 38.55, // 覆盖率报告部分
          'packageCoverage': 35.65, // 覆盖率报告部分
          'differentialResults': [
            {
              evm: 'Geth',
              result: '通过',
              gasUsed: '0xa3d', // Geth的Gas消耗
              stackState: '正常',
              storageState: '一致',
              output: '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
            },
            {
              evm: 'SealEVM',
              result: '失败',
              gasUsed: '0x6', // SealEVM的Gas消耗
              stackState: '异常',
              storageState: '不一致',
              error: 'no code for: 0x24d82e387fcccb6c675d75947bf2e8e09fbea57d' // SealEVM的错误信息
            }
          ],
          'issues': [
            { 'issueId': 'EXTCODESIZE', 'description': '外部合约调用失败，未找到合约代码', 'status': '待修复' },
            { 'issueId': 'PUSH20', 'description': 'Gas消耗差异', 'status': '待修复' },
            { 'issueId': 'RETURN', 'description': 'Geth返回有效输出，SealEVM未返回', 'status': '待修复' }
          ],
          'fixSuggestions': [
            { 'opcode': 'EXTCODESIZE', 'suggestion': '检查合约代码的部署状态或合约地址的正确性' },
            { 'opcode': 'PUSH20', 'suggestion': '优化合约代码逻辑，减少无效的Gas消耗' },
            { 'opcode': 'RETURN', 'suggestion': '确保SealEVM正确处理返回值' }
          ]
        },
        {
          'testCaseId': 'test2',
          'name': '长安链VM-evm漏洞修复',
          'platform': 'geth',
          'description': '执行操作码basefee返回值不正确，未采用genesis中设置的值',
          'date': '2024-08-08',
          'status': '已修复',
          'crashLog': 'Traceback (most recent call last):\n  File "/path/to/evm/evm.py", line 200, in execute\n    self.create_contract()\n  File "/path/to/evm/evm.py", line 150, in create_contract\n    raise Exception("BASEFEE value mismatch detected")\nException: BASEFEE value mismatch detected',
          'bytecode': '63b162569e75c903905b831',
          'result': '失败',
          'timeTaken': '3s',
          'startTime': '2024-10-13 10:00',
          'endTime': '2024-10-13 10:45',
          'testCount': 6,
          'executionLog': 'Traceback (most recent call last):File "/path/to/evm/evm.py", line 200, in execute self.create_contract() File "/path/to/evm/evm.py", line 150, in create_contract raise Exception("BASEFEE value mismatch detected")Exeption: BASEFEE value mismatch detected',
          'opcodeTrace': [
            { 'step': 1, 'opcode': 'BASEFEE', 'description': '获取区块的基础费用' },
            { 'step': 2, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 3, 'opcode': 'MSTORE', 'description': '将栈顶的值存入内存' },
            { 'step': 4, 'opcode': 'PUSH1', 'description': '将值40推入栈' },
            { 'step': 5, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 6, 'opcode': 'RETURN', 'description': '返回内存中的数据' }
          ],
          'rootCause': 'BASEFEE操作码未能使用genesis.json中指定的baseFeePerGas值，导致返回值不正确。',
          'functionCoverage': 38.55, // 覆盖率报告部分
          'packageCoverage': 35.65, // 覆盖率报告部分
          'differentialResults': [
            {
              evm: 'Geth',
              result: '通过',
              gasUsed: '0xa3d', // Geth的Gas消耗
              stackState: '正常',
              storageState: '一致',
              output: '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
            },
            {
              evm: 'SealEVM',
              result: '失败',
              gasUsed: '0x6', // SealEVM的Gas消耗
              stackState: '异常',
              storageState: '不一致',
              error: 'no code for: 0x24d82e387fcccb6c675d75947bf2e8e09fbea57d' // SealEVM的错误信息
            }
          ],
          'issues': [
            { 'issueId': 'EXTCODESIZE', 'description': '外部合约调用失败，未找到合约代码', 'status': '待修复' },
            { 'issueId': 'PUSH20', 'description': 'Gas消耗差异', 'status': '待修复' },
            { 'issueId': 'RETURN', 'description': 'Geth返回有效输出，SealEVM未返回', 'status': '待修复' }
          ],
          'fixSuggestions': [
            { 'opcode': 'EXTCODESIZE', 'suggestion': '检查合约代码的部署状态或合约地址的正确性' },
            { 'opcode': 'PUSH20', 'suggestion': '优化合约代码逻辑，减少无效的Gas消耗' },
            { 'opcode': 'RETURN', 'suggestion': '确保SealEVM正确处理返回值' }
          ]
        },
        {
          'testCaseId': 'test2',
          'name': 'Geth漏洞修复',
          'platform': 'geth',
          'description': '执行操作码basefee返回值不正确，未采用genesis中设置的值',
          'date': '2024-08-08',
          'status': '已修复',
          'crashLog': 'Traceback (most recent call last):\n  File "/path/to/evm/evm.py", line 200, in execute\n    self.create_contract()\n  File "/path/to/evm/evm.py", line 150, in create_contract\n    raise Exception("BASEFEE value mismatch detected")\nException: BASEFEE value mismatch detected',
          'bytecode': '60b35160005260406000f3',
          'result': '失败',
          'timeTaken': '3s',
          'startTime': '2024-10-17 18:00',
          'endTime': '2024-10-17 18:40',
          'testCount': 2,
          'executionLog': 'Traceback (most recent call last):File "/path/to/evm/evm.py", line 200, in execute self.create_contract() File "/path/to/evm/evm.py", line 150, in create_contract raise Exception("BASEFEE value mismatch detected")Exeption: BASEFEE value mismatch detected',
          'opcodeTrace': [
            { 'step': 1, 'opcode': 'BASEFEE', 'description': '获取区块的基础费用' },
            { 'step': 2, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 3, 'opcode': 'MSTORE', 'description': '将栈顶的值存入内存' },
            { 'step': 4, 'opcode': 'PUSH1', 'description': '将值40推入栈' },
            { 'step': 5, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 6, 'opcode': 'RETURN', 'description': '返回内存中的数据' }
          ],
          'rootCause': 'BASEFEE操作码未能使用genesis.json中指定的baseFeePerGas值，导致返回值不正确。',
          'functionCoverage': 38.55, // 覆盖率报告部分
          'packageCoverage': 35.65, // 覆盖率报告部分
          'differentialResults': [
            {
              evm: 'Geth',
              result: '通过',
              gasUsed: '0xa3d', // Geth的Gas消耗
              stackState: '正常',
              storageState: '一致',
              output: '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
            },
            {
              evm: 'SealEVM',
              result: '失败',
              gasUsed: '0x6', // SealEVM的Gas消耗
              stackState: '异常',
              storageState: '不一致',
              error: 'no code for: 0x24d82e387fcccb6c675d75947bf2e8e09fbea57d' // SealEVM的错误信息
            }
          ],
          'issues': [
            { 'issueId': 'EXTCODESIZE', 'description': '外部合约调用失败，未找到合约代码', 'status': '待修复' },
            { 'issueId': 'PUSH20', 'description': 'Gas消耗差异', 'status': '待修复' },
            { 'issueId': 'RETURN', 'description': 'Geth返回有效输出，SealEVM未返回', 'status': '待修复' }
          ],
          'fixSuggestions': [
            { 'opcode': 'EXTCODESIZE', 'suggestion': '检查合约代码的部署状态或合约地址的正确性' },
            { 'opcode': 'PUSH20', 'suggestion': '优化合约代码逻辑，减少无效的Gas消耗' },
            { 'opcode': 'RETURN', 'suggestion': '确保SealEVM正确处理返回值' }
          ]
        },
        {
          'testCaseId': 'test2',
          'name': 'Besu漏洞修复',
          'platform': 'geth',
          'description': '执行操作码basefee返回值不正确，未采用genesis中设置的值',
          'date': '2024-08-08',
          'status': '已修复',
          'crashLog': 'Traceback (most recent call last):\n  File "/path/to/evm/evm.py", line 200, in execute\n    self.create_contract()\n  File "/path/to/evm/evm.py", line 150, in create_contract\n    raise Exception("BASEFEE value mismatch detected")\nException: BASEFEE value mismatch detected',
          'bytecode': '7cc78e8203b7f546d82fc188',
          'result': '失败',
          'timeTaken': '3s',
          'startTime': '2024-10-18 17:00',
          'endTime': '2024-10-18 17:45',
          'testCount': 11,
          'executionLog': 'Traceback (most recent call last):File "/path/to/evm/evm.py", line 200, in execute self.create_contract() File "/path/to/evm/evm.py", line 150, in create_contract raise Exception("BASEFEE value mismatch detected")Exeption: BASEFEE value mismatch detected',
          'opcodeTrace': [
            { 'step': 1, 'opcode': 'BASEFEE', 'description': '获取区块的基础费用' },
            { 'step': 2, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 3, 'opcode': 'MSTORE', 'description': '将栈顶的值存入内存' },
            { 'step': 4, 'opcode': 'PUSH1', 'description': '将值40推入栈' },
            { 'step': 5, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 6, 'opcode': 'RETURN', 'description': '返回内存中的数据' }
          ],
          'rootCause': 'BASEFEE操作码未能使用genesis.json中指定的baseFeePerGas值，导致返回值不正确。',
          'functionCoverage': 38.55, // 覆盖率报告部分
          'packageCoverage': 35.65, // 覆盖率报告部分
          'differentialResults': [
            {
              evm: 'Geth',
              result: '通过',
              gasUsed: '0xa3d', // Geth的Gas消耗
              stackState: '正常',
              storageState: '一致',
              output: '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
            },
            {
              evm: 'SealEVM',
              result: '失败',
              gasUsed: '0x6', // SealEVM的Gas消耗
              stackState: '异常',
              storageState: '不一致',
              error: 'no code for: 0x24d82e387fcccb6c675d75947bf2e8e09fbea57d' // SealEVM的错误信息
            }
          ],
          'issues': [
            { 'issueId': 'EXTCODESIZE', 'description': '外部合约调用失败，未找到合约代码', 'status': '待修复' },
            { 'issueId': 'PUSH20', 'description': 'Gas消耗差异', 'status': '待修复' },
            { 'issueId': 'RETURN', 'description': 'Geth返回有效输出，SealEVM未返回', 'status': '待修复' }
          ],
          'fixSuggestions': [
            { 'opcode': 'EXTCODESIZE', 'suggestion': '检查合约代码的部署状态或合约地址的正确性' },
            { 'opcode': 'PUSH20', 'suggestion': '优化合约代码逻辑，减少无效的Gas消耗' },
            { 'opcode': 'RETURN', 'suggestion': '确保SealEVM正确处理返回值' }
          ]
        },
        {
          'testCaseId': 'test2',
          'name': 'EthereumJS',
          'platform': 'geth',
          'description': '执行操作码basefee返回值不正确，未采用genesis中设置的值',
          'date': '2024-08-08',
          'status': '已修复',
          'crashLog': 'Traceback (most recent call last):\n  File "/path/to/evm/evm.py", line 200, in execute\n    self.create_contract()\n  File "/path/to/evm/evm.py", line 150, in create_contract\n    raise Exception("BASEFEE value mismatch detected")\nException: BASEFEE value mismatch detected',
          'bytecode': '63d901b803f2a2597960',
          'result': '成功',
          'timeTaken': '3s',
          'startTime': '2024-10-20 19:00',
          'endTime': '2024-10-20 19:45',
          'testCount': 4,
          'executionLog': 'Traceback (most recent call last):File "/path/to/evm/evm.py", line 200, in execute self.create_contract() File "/path/to/evm/evm.py", line 150, in create_contract raise Exception("BASEFEE value mismatch detected")Exeption: BASEFEE value mismatch detected',
          'opcodeTrace': [
            { 'step': 1, 'opcode': 'BASEFEE', 'description': '获取区块的基础费用' },
            { 'step': 2, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 3, 'opcode': 'MSTORE', 'description': '将栈顶的值存入内存' },
            { 'step': 4, 'opcode': 'PUSH1', 'description': '将值40推入栈' },
            { 'step': 5, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 6, 'opcode': 'RETURN', 'description': '返回内存中的数据' }
          ],
          'rootCause': 'BASEFEE操作码未能使用genesis.json中指定的baseFeePerGas值，导致返回值不正确。',
          'functionCoverage': 38.55, // 覆盖率报告部分
          'packageCoverage': 35.65, // 覆盖率报告部分
          'differentialResults': [
            {
              evm: 'Geth',
              result: '通过',
              gasUsed: '0xa3d', // Geth的Gas消耗
              stackState: '正常',
              storageState: '一致',
              output: '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
            },
            {
              evm: 'SealEVM',
              result: '成功',
              gasUsed: '0x6', // SealEVM的Gas消耗
              stackState: '异常',
              storageState: '不一致',
              error: 'no code for: 0x24d82e387fcccb6c675d75947bf2e8e09fbea57d' // SealEVM的错误信息
            }
          ],
          'issues': [
            { 'issueId': 'EXTCODESIZE', 'description': '外部合约调用失败，未找到合约代码', 'status': '待修复' },
            { 'issueId': 'PUSH20', 'description': 'Gas消耗差异', 'status': '待修复' },
            { 'issueId': 'RETURN', 'description': 'Geth返回有效输出，SealEVM未返回', 'status': '待修复' }
          ],
          'fixSuggestions': [
            { 'opcode': 'EXTCODESIZE', 'suggestion': '检查合约代码的部署状态或合约地址的正确性' },
            { 'opcode': 'PUSH20', 'suggestion': '优化合约代码逻辑，减少无效的Gas消耗' },
            { 'opcode': 'RETURN', 'suggestion': '确保SealEVM正确处理返回值' }
          ]
        },
        {
          'testCaseId': 'test2',
          'name': 'Geth漏洞修复',
          'platform': 'geth',
          'description': '执行操作码basefee返回值不正确，未采用genesis中设置的值',
          'date': '2024-08-08',
          'status': '已修复',
          'crashLog': 'Traceback (most recent call last):\n  File "/path/to/evm/evm.py", line 200, in execute\n    self.create_contract()\n  File "/path/to/evm/evm.py", line 150, in create_contract\n    raise Exception("BASEFEE value mismatch detected")\nException: BASEFEE value mismatch detected',
          'bytecode': '8203b7f546d82fc188cb1869',
          'result': '失败',
          'timeTaken': '3s',
          'startTime': '2024-10-22 10:00',
          'endTime': '2024-10-22 10:45',
          'testCount': 6,
          'executionLog': 'Traceback (most recent call last):File "/path/to/evm/evm.py", line 200, in execute self.create_contract() File "/path/to/evm/evm.py", line 150, in create_contract raise Exception("BASEFEE value mismatch detected")Exeption: BASEFEE value mismatch detected',
          'opcodeTrace': [
            { 'step': 1, 'opcode': 'BASEFEE', 'description': '获取区块的基础费用' },
            { 'step': 2, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 3, 'opcode': 'MSTORE', 'description': '将栈顶的值存入内存' },
            { 'step': 4, 'opcode': 'PUSH1', 'description': '将值40推入栈' },
            { 'step': 5, 'opcode': 'PUSH1', 'description': '将值0推入栈' },
            { 'step': 6, 'opcode': 'RETURN', 'description': '返回内存中的数据' }
          ],
          'rootCause': 'BASEFEE操作码未能使用genesis.json中指定的baseFeePerGas值，导致返回值不正确。',
          'functionCoverage': 38.55, // 覆盖率报告部分
          'packageCoverage': 35.65, // 覆盖率报告部分
          'differentialResults': [
            {
              evm: 'Geth',
              result: '通过',
              gasUsed: '0xa3d', // Geth的Gas消耗
              stackState: '正常',
              storageState: '一致',
              output: '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
            },
            {
              evm: 'SealEVM',
              result: '失败',
              gasUsed: '0x6', // SealEVM的Gas消耗
              stackState: '异常',
              storageState: '不一致',
              error: 'no code for: 0x24d82e387fcccb6c675d75947bf2e8e09fbea57d' // SealEVM的错误信息
            }
          ],
          'issues': [
            { 'issueId': 'EXTCODESIZE', 'description': '外部合约调用失败，未找到合约代码', 'status': '待修复' },
            { 'issueId': 'PUSH20', 'description': 'Gas消耗差异', 'status': '待修复' },
            { 'issueId': 'RETURN', 'description': 'Geth返回有效输出，SealEVM未返回', 'status': '待修复' }
          ],
          'fixSuggestions': [
            { 'opcode': 'EXTCODESIZE', 'suggestion': '检查合约代码的部署状态或合约地址的正确性' },
            { 'opcode': 'PUSH20', 'suggestion': '优化合约代码逻辑，减少无效的Gas消耗' },
            { 'opcode': 'RETURN', 'suggestion': '确保SealEVM正确处理返回值' }
          ]
        }

      ],
      filteredReports: [], // 过滤后的测试报告列表
      testDetailsVisible: false, // 控制弹窗可见性
      testDetails: {}, // 当前选中的测试报告详情
      addReportVisible: false, // 控制新增报告弹窗可见性
      newReport: {
        bytecode: '',
        result: '',
        timeTaken: '',
        startTime: '',
        endTime: ''
      }, // 新增测试报告表单数据
      currentPage: 1,
      pageSize: 10
    }
  },
  mounted() {
    this.filterReports() // 初始化过滤器
  },
  methods: {
    // 根据测试报告筛选
    filterReports() {
      if (this.selectedTest === 'all') {
        this.filteredReports = this.testReports
      } else {
        this.filteredReports = this.testReports.filter(
          (report) => report.testCaseId === this.selectedTest
        )
      }
    },
    // 查看详细测试报告
    viewTestDetails(report) {
      this.testDetails = report
      this.testDetailsVisible = true
    },
    // 分页变更
    handlePageChange(page) {
      this.currentPage = page
    },
    // 搜索功能
    searchReports() {
      this.filterReports()
    },
    // 重置搜索条件
    resetSearch() {
      this.selectedTest = 'all'
      this.searchTest = ''
      this.filterReports()
    },
    // 新增测试报告
    addTestReport() {
      this.addReportVisible = true
    },
    // 保存新增测试报告
    saveNewReport() {
      this.testReports.push({ ...this.newReport })
      this.addReportVisible = false
      this.newReport = {
        bytecode: '',
        result: '',
        timeTaken: '',
        startTime: '',
        endTime: ''
      }
      this.filterReports()
    },
    // 导出测试报告
    exportReports() {
      const dataStr = JSON.stringify(this.testReports)
      const blob = new Blob([dataStr], { type: 'application/json' })
      const url = window.URL.createObjectURL(blob)
      const link = document.createElement('a')
      link.href = url
      link.download = 'test-reports.json'
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    },
    // 导入测试报告
    importReports() {
      const fileInput = document.createElement('input')
      fileInput.type = 'file'
      fileInput.accept = '.json'
      fileInput.onchange = (event) => {
        const file = event.target.files[0]
        const reader = new FileReader()
        reader.onload = (e) => {
          try {
            const importedData = JSON.parse(e.target.result)
            this.testReports = [...this.testReports, ...importedData]
            this.filterReports()
          } catch (err) {
            this.$message.error('导入失败，请检查文件格式')
          }
        }
        reader.readAsText(file)
      }
      fileInput.click()
    },
    // 过滤报告
    filterReports() {
      // 根据搜索条件过滤测试报告
      if (this.selectedTest === 'all') {
        this.filteredReports = this.testReports
      } else {
        this.filteredReports = this.testReports.filter(report => report.testCaseId === this.selectedTest)
      }
    },
    // 下载测试报告
    downloadReport(report) {
      const dataStr = JSON.stringify(report)
      const blob = new Blob([dataStr], { type: 'application/json' })
      const url = window.URL.createObjectURL(blob)
      const link = document.createElement('a')
      link.href = url
      link.download = `test-report-${report.startTime}.json`
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    }
  }
}
</script>

<style scoped>
.test-report {
  padding: 20px;
}

.search-section {
  margin-bottom: 20px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.action-buttons {
  margin-bottom: 20px;
}

.el-table {
  border-collapse: collapse;
  border: 1px solid #dcdfe6;
  margin-top: 20px;
}

.el-table th, .el-table td {
  border-right: 1px solid #dcdfe6;
}

.report-title {
  font-size: 24px;
  font-weight: bold;
  color: #409EFF;
  margin-bottom: 20px;
}
</style>
